package org.dromara.business.task;

import com.aizuda.snailjob.client.job.core.annotation.JobExecutor;
import com.aizuda.snailjob.client.job.core.dto.JobArgs;
import com.aizuda.snailjob.client.model.ExecuteResult;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.dromara.business.service.IUserStakingService;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


/**
 * 质押返利定时器
 */
@Slf4j
@Component
@JobExecutor(name = "dailyRebateTask")
public class DailyRebateTask {

    @Resource
    private IUserStakingService userStakingService;

    public ExecuteResult jobExecute(JobArgs jobArgs) {
        log.info("开始执行每日返利定时任务，执行时间：{}", LocalDateTime.now());
        try {
            userStakingService.processRebates(LocalDateTime.now());
            log.info("每日返利定时任务执行成功");
            return ExecuteResult.success("返利执行成功");
        } catch (Exception e) {
            log.error("每日返利定时任务执行失败", e);
            return ExecuteResult.success("返利执行失败");
        }
    }
}
